//
//  ViewController.m
//  选择食物
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property(nonatomic,strong)NSArray *list1;
@property(nonatomic,strong)NSArray *list2;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.list1=@[@"火腿",@"火鸡",@"花生酱",@"金枪鱼沙拉",@"鸡丁沙拉",@"烤牛肉"];
    self.list2=@[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnPressed:(id)sender {
//    [self.pickerView selectRow:2 inComponent:0 animated:YES];
//    [self.pickerView selectRow:0 inComponent:1 animated:YES];
    
    int sel1=[self.pickerView selectedRowInComponent:0];
    int sel2=[self.pickerView selectedRowInComponent:1];
    
    NSString *str=[NSString stringWithFormat:@"您选择了%@和%@",self.list1[sel1],self.list2[sel2]];
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:str delegate:nil cancelButtonTitle:@"重新选择" otherButtonTitles:@"确定", nil];
    [alert show];
    
    self.infoLabel.text=[NSString stringWithFormat:@"我的早饭是%@和%@",self.list1[sel1],self.list2[sel2]];
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (component==0) {
        return self.list1.count;
    }
    else{
        return self.list2.count;
    }
}

-(nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component==0) {
        return self.list1[row];
    }else{
        return self.list2[row];
    }
    
    
}


@end
